<%@page import="sdfi.lee.DAO.UserDAO"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="<c:url value='/css/common.css'></c:url>">
<link rel="stylesheet" href="<c:url value='/css/adnews.css'></c:url>" />
<script type="text/javascript" src="<c:url value='/js/jquery-1.6.js' />"></script>
<script type="text/javascript">
$(function(){
$(":checkbox").click(function(){
	var status=0;
	var cbinput=$(this);
	if($(this).is(':checked'))
			status=-1;
	else status=1;
	var opt={
			data:{ustatus:status,userid:cbinput.val()},
			dataType:"json",
			type:"post",
			url:"../changestatus",
			error:function(status,xhr){
				alert("系统出错啦");
			},
			success:function(data,status){
				if(data.status=="success")
					{
						
								var t=cbinput.next("label").text();
								cbinput.next("label").text(t=="解锁用户"?"锁定用户":"解锁用户");
								cbinput.parent().nextAll(":eq(3)").text(t=="解锁用户"?"未被锁定":"已被锁定");
					}
				else 
					{
						alert("更新失败");
					}
			}
	};
	$.ajax(opt);
	});
	$("#show").hide();
	$("td>a").click(function(){
		$("#showdetail").load($(this).attr("href"),{},function(status,xhr){
			$("#show").css("height",$(document).height()).css("width",$(document).width()/2);
			$("#show").slideDown();
			$("table").hide();
		
		});
		return false;
	});
	$("#showhead").click(function(){
		$("#show").slideUp();
		$("table").show();
	});
});
	
</script>
<title>Insert title here</title>
</head>
<body style="height:400px">
	<%
		Integer pg=Integer.valueOf(request.getParameter("pg"));
		UserDAO userdao=new UserDAO();
		request.setAttribute("list",userdao.getAlluser(pg,5));
	%>
	
	<div id="show">
	
			<div id="showhead"><span>关闭</span></div>
			<div id="showdetail">
	
				正在加载.....
			</div>
	
	</div>
	
	<table>
		<tr>
			<th>
				锁定用户
			</th>
			<th>
				公司名
			</th>
			<th>
				联系人
			</th>
			<th>
				用户名
			</th>
			<th>
				用户状态
			</th>
			<th>
				查看
			</th>
		</tr>
		<c:if test="${requestScope.list!=null&&(fn:length(requestScope.list)>0)}">
			<c:forEach items="${requestScope.list}" var="user" varStatus="status">
				<tr>
					<td>
						<input value="${user.id}" type="checkbox" <c:if test="${user.id==-1}">checked</c:if>>
						<label>
							<c:choose>
								<c:when test="${user.ustatus==-1}">
									解锁用户
								</c:when>
								<c:otherwise>
									锁定用户
								</c:otherwise>
							</c:choose>
						</label>
					</td>
					<td>
						<c:choose>
							<c:when test="${user.company==null}">
								暂未填写
							</c:when>
							<c:otherwise>
								${user.company}
							</c:otherwise>
						</c:choose>
					
					</td>
					<td>
					<c:choose>
							<c:when test="${user.linkman==null}">
								暂未填写
							</c:when>
							<c:otherwise>
								${user.linkman}
							</c:otherwise>
						</c:choose>
					</td>
					<td>
						${user.username}
					</td>
					<td>
						<c:choose>
						<c:when test="${user.ustatus==1}">
								未被锁定
							</c:when>
							<c:otherwise>
								已被锁定
							</c:otherwise>
							</c:choose>
					</td>
					<td>
						<a href="<c:url value='/admin/userdetail.jsp?userid=${user.id}'/>">查看</a>
					</td>
				</tr>
			</c:forEach>
		</c:if>
	</table>
	<div id="pages" style="text-align:center">
		<c:url var="up" value="/admin/usermg.jsp">
			<c:param name="pg" value="${param.pg-1}"></c:param>
		</c:url>
		<c:url var="down" value="/admin/usermg.jsp">
			<c:param name="pg" value="${param.pg+1}"></c:param>
		</c:url>
			<font>
				<c:if test="${param.pg==1}">&lt;</c:if>
				<c:if test="${param.pg!=1}"><a href="${up}">&lt;</a></c:if>
			</font>
			<font>
				${param.pg}
			</font>
			<font>
				<c:choose>
					<c:when test="${fn:length(requestScope.list)<5}">&gt;</c:when>
					<c:otherwise><a href="${down}">&gt;</a></c:otherwise>
				</c:choose>
			</font>
		
	</div>
</body>
</html>